package study.singleton;

import java.io.Serializable;

public class LazySingleton implements Serializable {

    private  volatile static LazySingleton lazySingleton = null;
    private LazySingleton (){
        if(null != lazySingleton){
            //防止反射强吻
            throw  new RuntimeException("不能重复创建");
        }
    }

    public LazySingleton getInstance(){
        if(lazySingleton == null){
            synchronized (LazySingleton.class){//双重
                if(lazySingleton == null){
                    lazySingleton = new LazySingleton();
                }
            }
        }
    return  lazySingleton;
    }

    private Object readResolve(){
        return lazySingleton;
    }
}
